Skip to content

[Cosmos] N-Region Synchronous Commit: Propagate SDK Supported Capabilities to BE With Data Plane and Barrier Requests#48965

Merged
kundadebdatta merged 10 commits intomainfrom
users/kundadebdatta/add_sdk_supported_capabilities
Apr 29, 2026
Merged

[Cosmos] N-Region Synchronous Commit: Propagate SDK Supported Capabilities to BE With Data Plane and Barrier Requests#48965
kundadebdatta merged 10 commits intomainfrom
users/kundadebdatta/add_sdk_supported_capabilities

Conversation

@kundadebdatta
Copy link
Copy Markdown
Member

@kundadebdatta kundadebdatta commented Apr 28, 2026

Description

Background

This PR enables the N-Region Synchronous Commit feature by ensuring the Cosmos DB Java SDK advertises its supported capabilities to the backend on all request paths — including barrier requests, which were previously missing this header.

Motivation

The N-Region Synchronous Commit flow requires the backend (BE) to return new RNTBD response tokens (e.g., GlobalNRegionCommittedGLSN) that older SDK versions would not recognize. The SDK must signal via the x-ms-cosmos-sdk-supportedcapabilities header that it can safely ignore unrecognized RNTBD tokens. Without this header on barrier requests, the BE cannot return the N-Region commit LSN during barrier operations.


Changes

1. HttpConstants.java — Expanded SDK Supported Capabilities (+14 / −5)

  • Added new capability flags:
    • THROUGHPUT_BUCKETING (1 << 2 = 4)
    • IGNORE_UNKNOWN_RNTBD_TOKENS (1 << 3 = 8) — signals that the SDK can handle unrecognized RNTBD transport tokens
    • CHANGE_FEED_TOKEN_WITH_GCN (1 << 4 = 16)
  • Updated SUPPORTED_CAPABILITIES from PARTITION_MERGE | CHANGE_FEED_WITH_START_TIME_POST_MERGE (value 3) to PARTITION_MERGE | CHANGE_FEED_WITH_START_TIME_POST_MERGE | IGNORE_UNKNOWN_RNTBD_TOKENS (value 11)
  • Changed capability field visibility from private to package-private (static final) to enable unit test access
  • Added documentation comments explaining the purpose of IGNORE_UNKNOWN_RNTBD_TOKENS
  • Switched to consistent 1 << N notation for all bit-shift definitions

2. BarrierRequestHelper.java — Attach Capabilities Header to Barrier Requests (+3 / −0)

  • Added the SDK_SUPPORTED_CAPABILITIES header with the value of SDKSupportedCapabilities.SUPPORTED_CAPABILITIES to barrier requests created by BarrierRequestHelper.createAsync()
  • Previously, barrier requests only included X_DATE, TARGET_LSN, TARGET_GLOBAL_COMMITTED_LSN, AUTHORIZATION, PARTITION_KEY, and COLLECTION_RID headers — now they also advertise the SDK's supported capabilities

3. BarrierRequestHelperTest.java — Test Coverage for Barrier Requests (+2 / −0)

  • Added assertion in barrierDocumentReadNameBasedRequest test to verify the SDK_SUPPORTED_CAPABILITIES header is present on barrier requests with the expected value

4. SDKSupportedCapabilitiesTest.java — New Unit Test File (+74 / −0)

  • capabilityBitValues: Validates each individual capability flag has the correct numeric value (0, 1, 2, 4, 8, 16)
  • capabilityBitsDoNotOverlap: Ensures no two capability flags share the same bit position
  • supportedCapabilitiesIncludesExpectedFlags: Verifies the combined SUPPORTED_CAPABILITIES string equals the expected bitwise OR of PARTITION_MERGE | CHANGE_FEED_WITH_START_TIME_POST_MERGE | IGNORE_UNKNOWN_RNTBD_TOKENS
  • supportedCapabilitiesNone: Confirms SUPPORTED_CAPABILITIES_NONE equals "0"
  • supportedCapabilitiesNumericValue: Asserts SUPPORTED_CAPABILITIES is "11"
  • supportedCapabilitiesContainsIgnoreUnknownRntbdTokens: Bitwise checks that IGNORE_UNKNOWN_RNTBD_TOKENS is set in the final capabilities value

5. CHANGELOG.md — Release Notes Entry (+1 / −0)

  • Added entry under 4.80.0-beta.1 > Features Added documenting the new capability flag and barrier request propagation

Files Changed Summary

File Changes Purpose
sdk/cosmos/azure-cosmos/src/main/java/.../HttpConstants.java +14 / −5 Add new capability flags, include IGNORE_UNKNOWN_RNTBD_TOKENS in default capabilities
sdk/cosmos/azure-cosmos/src/main/java/.../BarrierRequestHelper.java +3 / −0 Propagate SDK_SUPPORTED_CAPABILITIES header to barrier requests
sdk/cosmos/azure-cosmos-tests/.../BarrierRequestHelperTest.java +2 / −0 Assert capabilities header on barrier requests
sdk/cosmos/azure-cosmos-tests/.../SDKSupportedCapabilitiesTest.java +74 / −0 Comprehensive unit tests for capability bit definitions
sdk/cosmos/azure-cosmos/CHANGELOG.md +1 / −0 Document the feature addition

How to Verify

  1. Unit tests: Run SDKSupportedCapabilitiesTest (group: unit) to validate capability bit definitions and the composed value
  2. Direct-mode tests: Run BarrierRequestHelperTest (group: direct) to confirm the SDK_SUPPORTED_CAPABILITIES header is present on barrier requests
  3. Manual verification: Confirm that the x-ms-cosmos-sdk-supportedcapabilities header value is "11" on both data-plane and barrier requests

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

@kundadebdatta kundadebdatta self-assigned this Apr 28, 2026
kundadebdatta and others added 2 commits April 28, 2026 17:29
- Add '// Visible for testing' comment on package-private constants
- Use 1 << 0 for PARTITION_MERGE for consistency with other bit flags
- Add doc comment on IGNORE_UNKNOWN_RNTBD_TOKENS explaining its purpose

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@kundadebdatta kundadebdatta marked this pull request as ready for review April 29, 2026 04:35
Copilot AI review requested due to automatic review settings April 29, 2026 04:35
@kundadebdatta kundadebdatta requested review from a team as code owners April 29, 2026 04:35
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Enables Cosmos DB N-Region Synchronous Commit negotiation by ensuring the SDK-supported capabilities header is propagated on barrier request paths, and by expanding/validating the SDK capability bitmask definitions.

Changes:

  • Add additional SDK capability flags and include IGNORE_UNKNOWN_RNTBD_TOKENS in the default supported capabilities value.
  • Attach x-ms-cosmos-sdk-supportedcapabilities to barrier requests.
  • Add/extend unit tests to validate capability bits and barrier header propagation; update changelog.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/BarrierRequestHelper.java Adds SDK supported capabilities header to barrier requests.
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/HttpConstants.java Expands capability flags and updates default supported capabilities composition.
sdk/cosmos/azure-cosmos/CHANGELOG.md Documents the new capability flag and barrier propagation.
sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/directconnectivity/BarrierRequestHelperTest.java Verifies barrier requests include the capabilities header.
sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/SDKSupportedCapabilitiesTest.java Adds tests validating capability bit values and composed supported capabilities.

Copy link
Copy Markdown
Member

@FabianMeiswinkel FabianMeiswinkel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think THROUGHPUT_BUCKETING should also be enabled? Or what exactly is gated behind this flag?

Copy link
Copy Markdown
Member

@FabianMeiswinkel FabianMeiswinkel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kundadebdatta kundadebdatta enabled auto-merge (squash) April 29, 2026 19:00
Copy link
Copy Markdown
Member

@xinlian12 xinlian12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

@kundadebdatta kundadebdatta merged commit 5ec0490 into main Apr 29, 2026
43 checks passed
@kundadebdatta kundadebdatta deleted the users/kundadebdatta/add_sdk_supported_capabilities branch April 29, 2026 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants